//
//  DropListViewController.m
//  UILbrary
//
//  Created by mac on 16/7/11.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "DropListViewController.h"
#import "DropListView.h"

@interface DropListViewController ()
{
    UIView *listBGview;
    UITableView *listTableView;
    NSArray *titleArr;
    CGFloat kDropListViewOrignX;
}
@property (nonatomic, strong) UIButton *dropButton;
@end

@implementation DropListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    [self configSubViews];
    
    
    
}



#pragma mark -- private methods




- (void)configSubViews{
    [self.view addSubview:self.dropButton];

//    [self addListView];
}


#pragma mark - updateConstraint
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.dropButton.frame = CGRectMake(100, 300, 100, 40);
}



#pragma mark - lazy


- (UIButton *)dropButton{
    if (!_dropButton) {
        _dropButton = ({
            UIButton *button = [[UIButton alloc] init];
            button.backgroundColor = [UIColor colorWithRed:0.4 green:0.888 blue:0.23 alpha:1.0];
            [button setTitle:@"下拉列表" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(dropButtonCLick) forControlEvents:UIControlEventTouchUpInside];
            button;
        });
    }
    return _dropButton;
}

- (void)dropButtonCLick{
    
    
    CGFloat dropViewWith = 150;
    //这里即使多次添加  DropListView 我们手动不释放，系统也会帮我们释放，系统会在我们的二次创建的时候去释放
    kDropListViewOrignX = (CGRectGetMaxX(self.dropButton.frame) - self.dropButton.frame.size.width/2.0) - dropViewWith/2.0;
    DropListView *listView = [[DropListView alloc] initWithFrame:CGRectMake(kDropListViewOrignX, CGRectGetMaxY(self.dropButton.frame), dropViewWith, 200)];
    listView.titleArr = @[@"苹果",@"华为",@"小米",@"魅族"];
    listView.dropListTableCellHeigh = 200/listView.titleArr.count;
    listView.tabClickBlock = ^(id objc, NSIndexPath *indexPath){
        if ([objc class] == NSClassFromString(@"__NSCFConstantString") ) {
            NSLog(@"点击了--%@",objc);
        }
        switch (indexPath.row) {
            case 0:
            {
               NSLog(@"点击了第0个cell");
            }
               
            break;
            case 1:
            {
                NSLog(@"点击了第1个cell");
            }
                
                break;
            case 2:
            {
                NSLog(@"点击了第2个cell");
            }
                
                break;
            case 3:
            {
                NSLog(@"点击了第3个cell");
            }
                
                break;
                
            default:
                break;
        }
    };
    [listView showDropListView];
    
   

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



/*
 
 1.快速点击button 时候，listBGview 重复加载，这个时候有两个方法来解决
   - 1，解决button 的快速重复点击 //http://www.jianshu.com/p/7b83e7e44149
   - 2. 对listBGview进行懒加载，这样保证listBGview只加载一次
 
 
 */

@end
